<template>
  <div id="otc">
    <div class="in">
      <div class="title">
        <img src="../../assets/img/zhuangshi.png" alt />
        <h4>otc入金</h4>
      </div>
      <div class="in-content">
        <div class="aisle">
          <!-- <span class="aisleActive">通道一</span>
          <span>通道二</span>
          <span>通道三</span>-->
        </div>
        <ul class="table">
          <li>
            <div>姓名</div>
            <div>购买数量</div>
          </li>
          <li>
            <div>
              <el-input style="width:200px" size="small" v-model="inGold.payer" placeholder="请输入姓名"></el-input>
            </div>
            <div style="display:flex">
              <el-input size="small" v-model="inGold.amount" placeholder="请输入购买数量">
                <template slot="append">USDT</template>
              </el-input>

              <el-button
                :loading="inGoldLoad"
                style="margin-left:100px"
                @click="getGold"
                plain
                type="warning"
                size="small"
                slot="reference"
              >提交</el-button>
            </div>
          </li>
        </ul>
        <div class="error">
          <img src="../../assets/img/tishi.png" alt />
          <span>请核对填写的信息，提交后不可更改</span>
        </div>
      </div>
    </div>
    <div class="in">
      <div class="title">
        <img src="../../assets/img/zhuangshi.png" alt />
        <h4>otc出金</h4>
      </div>
      <div class="in-content">
        <ul class="table">
          <li>
            <div>出金数量</div>
          </li>
          <li>
            <div style="display:flex;width:650px">
              <el-input size="small" v-model="lossGold.amount" placeholder="请输入内容">
                <template slot="append">USDT</template>
              </el-input>
              <el-button
                :loading="outGoldLoad"
                style="margin-left:100px"
                @click.native="outGold"
                plain
                type="warning"
                size="small"
                slot="reference"
              >提交</el-button>
            </div>
          </li>
        </ul>
        <div class="error">
          <img src="../../assets/img/tishi.png" alt />
          <span>请核对填写的信息，提交后不可更改</span>
        </div>
      </div>
    </div>
    <div class="tablelist">
      <el-tabs
        v-loading="load"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        v-model="activeName"
      >
        <el-tab-pane label="入金记录" name="first">
          <el-table height="300px" :data="inLists" stripe style="width: 100%">
            <el-table-column prop="statusName" label="状态" min-width="180"></el-table-column>
            <el-table-column prop="amount" label="入金数量" min-width="180"></el-table-column>
            <el-table-column prop="orderTime" label="入金时间" min-width="180"></el-table-column>
          </el-table>
          <el-pagination
            @current-change="nextPage1"
            style="text-align:center;margin-top:20px;"
            small
            layout="prev, pager, next"
            :total="total1"
            :page-size="7"
          ></el-pagination>
        </el-tab-pane>

        <el-tab-pane label="出金记录" name="second">
          <el-table height="300px" :data="outLists" stripe style="width: 100%">
            <el-table-column prop="statusName" label="状态" min-width="180"></el-table-column>
            <el-table-column prop="userName" label="姓名" min-width="180"></el-table-column>
            <el-table-column prop="amount" label="出金数量" min-width="180"></el-table-column>
            <el-table-column prop="otcRatio" label="汇率" min-width="180"></el-table-column>
            <el-table-column prop="createTime" label="入金时间" min-width="180"></el-table-column>
            
          </el-table>
          <el-pagination
            @current-change="nextPage2"
            style="text-align:center;margin-top:20px;"
            small
            layout="prev, pager, next"
            :total="total2"
            :page-size="7"
          ></el-pagination>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import { otcBuy, otcSale, otcList, otcSalelist } from "../../api/api";
import { mapState } from "vuex";
import qs from "qs";
import { dataURLtoFile } from "image-conversion";
export default {
  name: "otc",
  data() {
    return {
      //入金
      inGoldLoad: false,
      inGold: {
        payer: "",
        amount: ""
      },
      inLists: [],
      total1:10,
      page1:1,
      //出金
      outGoldLoad: false,
      lossGold: {
        amount: ""
      },
      total2:10,
      page2:1,
      outLists: [],
      activeName: "first",
      load: false
    };
  },
  computed: {
    ...mapState(["token", "userMessage"])
  },
  created() {
    this.inList();
    this.outList();
  },
  methods: {
    //提交入金
    getGold() {
      this.inGoldLoad = true;
      var params = {
        token: this.token,
        amount: this.inGold.amount,
        payer: this.inGold.payer
      };
      otcBuy(qs.stringify(params)).then(res => {
        this.inGoldLoad = false;
        if (res.data.code == 200) {
          this.inList();
          this.$notify({
            title: "提示",
            message: "提交成功！",
            type: "success"
          });
        } else {
          this.$notify({
            title: "警告",
            message: res.data.msg || res.data.chineseMessage,
            type: "warning"
          });
        }
      });
    },
    //出金
    outGold() {
      this.outGoldLoad = true;
      var params = {
        token: this.token,
        amount: this.lossGold.amount,
        bankId: this.userMessage.id
      };

      otcSale(qs.stringify(params)).then(res => {
        this.outGoldLoad = false;
        if (res.data.code == 200) {
          this.outList();
          this.$notify({
            title: "提示",
            message: "提交成功！",
            type: "success"
          });
        } else {
          this.$notify({
            title: "警告",
            message: res.data.msg || res.data.chineseMessage,
            type: "warning"
          });
        }
      });
    },
    //入金记录
    inList() {
      this.load = true;
      var params = {
        pageNum: this.page1,
        pageSize: 7,
        token: this.token
      };
      otcList(qs.stringify(params)).then(res => {
        this.load = false;
        this.inLists = res.data.data;
        this.total1 = res.data.count
      });
    },
    nextPage1(val){
      this.page1 = val
      this.inList()
    },
    //出金记录
    outList() {
      this.load = true;
      var params = {
        pageNum: this.page2,
        pageSize: 7,
        token: this.token
      };
      otcSalelist(qs.stringify(params)).then(res => {
        this.load = false;
        this.outLists = res.data.data;
        this.total2 = res.data.count
      });
    },
    nextPage2(val){
      this.page2 = val
      this.outList()
    },
  }
};
</script>
<style lang='less' scope>
#otc {
  .title {
    position: relative;
    > img {
      position: absolute;
      top: 4px;
    }
    > h4 {
      margin-left: 50px;
    }
  }
  .aisleActive {
    border: 1px solid#DBB783 !important;
    color: #dbb783 !important;
  }
  .in {
    .table {
      .el-input__inner,
      .el-input-group__append,
      .el-input-group__prepend {
        background-color: #faf9f7 !important;
        border: 1px solid #faf9f7 !important;
      }
    }
  }
  .btn {
    text-align: center;
    font-size: 15px;
    color: #fff;
    background-image: linear-gradient(to right, #cfa66e, #fbe0b8);
    padding: 6px 0;
    border-radius: 4px;
    width: 180px;
    margin-left: 20px;
  }
  .error {
    background-color: #fffaf7;
    font-size: 14px;
    color: #ff6057;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 8px 10px;
    span {
      margin-left: 20px;
    }
  }
  // --------------------
  .in {
    background-color: #fff;
    padding: 15px;
    margin-bottom: 10px;
    .in-content {
      width: 80%;
      margin: 30px 0 20px 50px;
      > .aisle {
        span {
          font-size: 14px;
          color: #a1b1b0;
          border: 1px solid #a1b1b0;
          padding: 6px 15px;
          margin-right: 20px;
        }
      }
      > .table {
        margin: 30px 0 20px;
        > li {
          display: flex;
          color: #334d50;
          font-size: 15px;
          margin-bottom: 10px;
          > div:nth-child(1) {
            width: 250px;
          }
          > div:nth-child(2) {
            width: 400px;
          }
        }
      }
    }
  }
  .tablelist {
    min-height: 300px;
    background-color: #fff;
  }
  // ----------------------
  .el-tabs {
    background-color: #fff;
  }
  .el-tabs__item.is-active {
    color: #0a9187;
  }
  .el-tabs__item:hover {
    color: #0a9187;
  }
  .el-tabs__active-bar {
    background-color: #0a9187;
  }
  .el-table {
    font-size: 12px;
  }
  .el-table td,
  .el-table th {
    padding: 6px 0;
  }

  // ----------------------
}
</style>